var ex=[8,95,34,21,53,12];
for (let i = 0; i < ex.length -1; i++) {
  for (let j = 0; j <ex.length - i - 1; j++) {
    if(ex[j] > ex[j+1]) {
      let temp = ex[j]
      ex[j] = ex[j+1]
      ex[j+1] = temp
    }
  }
}
console.log(ex)

// 封装一下
function bubbleSort(arr) {
  if (arr.length <= 1) {
    return arr
  }
  for (let i = 0; i < arr.length -1; i++) {
    for (let j = 0; j <arr.length - i - 1; j++) {
      if(arr[j] > arr[j+1]) {
        let temp = arr[j]
        arr[j] = arr[j+1]
        arr[j+1] = temp
      }
    }
  }
  return arr
}
bubbleSort(ex)
console.log(ex)